<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //倒计时  起始时间  目标时间
      function downCount(end) {
        var start = new Date();
        //求2个时间的差值    毫秒值
        var ms = +end - +start;
        var s = ms / 1000; //7200
        //转为日时分秒 //带入法26小时 1天2小时
        var dd = parseInt(s / 60 / 60 / 24); //得到天
        var hh = Math.floor((s / 60 / 60) % 24); //小时
        var mm = Math.floor((s / 60) % 60); //分
        var ss = Math.floor(s % 60); //秒
        console.log(dd,hh,mm,ss);
        return {
            tian:dd,
            xiaoshi:hh,
            fenzhong:mm,
            miao:ss
        }
      }
       var result =  downCount(new Date('2020-08-27 17:50:00'));
       console.log(result);
       document.write('距离下课时间'+ result.tian+'天'+result.xiaoshi+'小时'+result.fenzhong+'分钟'+result.miao+'秒')
    </script>
  </body>
</html>

